﻿Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Public Class DAOGeneral
    '//////////////////////////////////////METODOS PARA LOS BARRIOS/////////////////////////////////

    'carga la grilla del form barrio
    Public Function cargarTablaCompuesta() As DataTable
        Dim tablaAux As New Data.DataTable
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Dim sql As String = "select b.id_barrio AS 'ID_BARRIO',b.nombre AS 'BARRIO',"
        sql &= "l.id_localidad AS 'ID_LOCALIDAD', l.nombre AS 'LOCALIDAD' "
        sql &= "from T_BARRIOS b, T_LOCALIDADES l "
        sql &= "where b.id_localidad=l.id_localidad"

        cn.Open()
        Dim cmd As New SqlCommand
        cmd.Connection = cn
        cmd.CommandText = sql
        cmd.CommandType = CommandType.Text

        tablaAux.Load(cmd.ExecuteReader())


        cn.Close()

        Return tablaAux

    End Function

    'Función para eliminar registros de FrmBarrios
    Public Function EliminarBarrio(ByVal pk As Integer) As Boolean

        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Try
            cn.Open()
            Dim sql As New SqlCommand("barrios_ELIMINAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@ID_BARRIO", SqlDbType.Int)
            sql.Parameters("@ID_BARRIO").Value = pk

            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()

        End Try

    End Function

    'Metodo para guardar Barrio
    Public Function GuardarBarrio(ByVal nombreBarrio As String, ByRef idLocalidad As Integer) As Boolean
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Try
            cn.Open()
            Dim sql As New SqlCommand("barrios_INSERTAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@NOMBRE", SqlDbType.NVarChar)
            sql.Parameters("@NOMBRE").Value = nombreBarrio

            sql.Parameters.Add("@ID_LOCALIDAD", SqlDbType.Int)
            sql.Parameters("@ID_LOCALIDAD").Value = idLocalidad

            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()

        End Try

    End Function

    'Metodo para modificar/actualizar Barrio
    Public Function ActualizarBarrio(ByRef nombreBarrio As String, ByRef idLocalidad As Integer, ByRef idBarrio As Integer) As Boolean
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Try
            cn.Open()
            Dim sql As New SqlCommand("barrios_EDITAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@ID_BARRIO", SqlDbType.Int)
            sql.Parameters("@ID_BARRIO").Value = idBarrio

            sql.Parameters.Add("@ID_LOCALIDAD", SqlDbType.Int)
            sql.Parameters("@ID_LOCALIDAD").Value = idLocalidad

            sql.Parameters.Add("@NOMBRE", SqlDbType.NVarChar)
            sql.Parameters("@NOMBRE").Value = nombreBarrio

            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()

        End Try
    End Function

    'metodo para ir filtrando barrios a medida que escribo
    Public Function buscarBarrioXNombre(ByVal nombre As String) As Data.DataTable 'metodo para filtrar localidades por el nombre
        Dim tabla As New Data.DataTable
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Dim sql As String = ""

        Try
            cn.Open()

            If nombre = "" Then 'pregunto si nombre viene vacio, es xq busco todos las localidades cargados
                sql = "select b.id_barrio AS 'ID_BARRIO',b.nombre AS 'BARRIO',"
                sql &= "l.id_localidad AS 'ID_LOCALIDAD', l.nombre AS 'LOCALIDAD' "
                sql &= "from T_BARRIOS b, T_LOCALIDADES l "
                sql &= "where b.id_localidad=l.id_localidad"
                Dim cmd As New SqlCommand()

                cmd.Connection = cn
                cmd.CommandText = sql
                cmd.CommandType = CommandType.Text
                tabla.Load(cmd.ExecuteReader())

            Else
                sql = "select b.id_barrio AS 'ID_BARRIO',b.nombre AS 'BARRIO',"
                sql &= "l.id_localidad AS 'ID_LOCALIDAD', l.nombre AS 'LOCALIDAD' "
                sql &= "from T_BARRIOS b, T_LOCALIDADES l "
                sql &= "where b.id_localidad=l.id_localidad and b.NOMBRE LIKE '%'+@NOMBRE+'%'"
                Dim cmd As New SqlCommand()

                cmd.Parameters.AddWithValue("@NOMBRE", nombre)
                cmd.Connection = cn
                cmd.CommandText = sql
                cmd.CommandType = CommandType.Text
                tabla.Load(cmd.ExecuteReader())
            End If

        Catch ex As Exception
        Finally
            cn.Close()
        End Try
        Return tabla
    End Function



    '/////////////////////////METODOS PARA LOCALIDAD////////////////////////////

    'metodo para cargar la tabla localidad
    Public Function cargarTabla() As DataTable
        Dim tablaAux As New Data.DataTable
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Dim sql As String = "Select * from T_LOCALIDADES"

        cn.Open()
        Dim cmd As New SqlCommand
        cmd.Connection = cn
        cmd.CommandText = sql
        cmd.CommandType = CommandType.Text

        tablaAux.Load(cmd.ExecuteReader())
        cn.Close()
        Return tablaAux

    End Function



    Public Function buscarLocalidadXNombre(ByVal nombre As String) As Data.DataTable 'metodo para filtrar localidades por el nombre
        Dim tabla As New Data.DataTable
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Dim sql As String = ""

        Try
            cn.Open()

            If nombre = "" Then 'pregunto si nombre viene vacio, es xq busco todos las localidades cargados
                sql = "select * from T_LOCALIDADES"
                Dim cmd As New SqlCommand()

                cmd.Connection = cn
                cmd.CommandText = sql
                cmd.CommandType = CommandType.Text
                tabla.Load(cmd.ExecuteReader())

            Else
                Dim sql1 As New SqlCommand("localidades_BUSCAR", cn)
                sql1.CommandType = CommandType.StoredProcedure

                sql1.Parameters.Add("@NOMBRE", SqlDbType.NVarChar)
                sql1.Parameters("@NOMBRE").Value = nombre
                tabla.Load(sql1.ExecuteReader())
            End If

        Catch ex As Exception
        Finally
            cn.Close()
        End Try
        Return tabla
    End Function


    'Metodo para guardar Localidad
    Public Function GuardarLocalidad(ByVal nombreLocalidad As String) As Boolean
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Try
            cn.Open()
            Dim sql As New SqlCommand("localidades_INSERTAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@NOMBRE", SqlDbType.NVarChar)
            sql.Parameters("@NOMBRE").Value = nombreLocalidad

            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()

        End Try

    End Function

    'metodo para actualizar una localidad
    Public Function ActualizarLocalidad(ByRef nombreLocalidad As String, ByRef idLocalidad As Integer) As Boolean
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Try
            cn.Open()
            Dim sql As New SqlCommand("localidades_EDITAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@ID_LOCALIDAD", SqlDbType.Int)
            sql.Parameters("@ID_LOCALIDAD").Value = idLocalidad

            sql.Parameters.Add("@NOMBRE", SqlDbType.NVarChar)
            sql.Parameters("@NOMBRE").Value = nombreLocalidad

            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()

        End Try
    End Function

    Public Function EliminarLocalidad(ByVal pk As Integer) As Boolean

        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Try
            cn.Open()
            Dim sql As New SqlCommand("localidades_ELIMINAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@ID_LOCALIDAD", SqlDbType.Int)
            sql.Parameters("@ID_LOCALIDAD").Value = pk

            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()
        End Try
    End Function


    '/////////////////////////////////////RUBROS/////////////////////////

    'metodo para cargar la tabla rubro
    Public Function cargarTablaRubro() As DataTable
        Dim tablaAux As New Data.DataTable
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Dim sql As String = "Select * from T_RUBROS"

        cn.Open()
        Dim cmd As New SqlCommand
        cmd.Connection = cn
        cmd.CommandText = sql
        cmd.CommandType = CommandType.Text

        tablaAux.Load(cmd.ExecuteReader())
        cn.Close()
        Return tablaAux

    End Function


    Public Function EliminarRubro(ByVal pk As Integer) As Boolean

        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Try
            cn.Open()
            Dim sql As New SqlCommand("rubros_ELIMINAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@ID_RUBRO", SqlDbType.Int)
            sql.Parameters("@ID_RUBRO").Value = pk

            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()
        End Try
    End Function


    Public Function GuardarRubros(ByVal rubro As String, ByVal descrip As String) As Boolean
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Try
            cn.Open()
            Dim sql As New SqlCommand("rubros_INSERTAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@NOMBRE", SqlDbType.NVarChar)
            sql.Parameters("@NOMBRE").Value = rubro

            If descrip = "" Then ' si no ingresa una descripcion debo mandar un dbnull
                sql.Parameters.Add("@DESCRIPCION", SqlDbType.NVarChar)
                sql.Parameters("@DESCRIPCION").Value = DBNull.Value
            Else
                sql.Parameters.Add("@DESCRIPCION", SqlDbType.NVarChar)
                sql.Parameters("@DESCRIPCION").Value = descrip
            End If

            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()

        End Try

    End Function


    Public Function buscarRubroXNombre(ByVal nombre As String) As Data.DataTable 'metodo para filtrar localidades por el nombre
        Dim tabla As New Data.DataTable
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Dim sql As String = ""

        Try
            cn.Open()

            If nombre = "" Then 'pregunto si nombre viene vacio, es xq busco todos las localidades cargados
                sql = "select * from T_RUBROS"
                Dim cmd As New SqlCommand()

                cmd.Connection = cn
                cmd.CommandText = sql
                cmd.CommandType = CommandType.Text
                tabla.Load(cmd.ExecuteReader())

            Else
                Dim sql1 As New SqlCommand("rubros_BUSCAR", cn)
                sql1.CommandType = CommandType.StoredProcedure

                sql1.Parameters.Add("@NOMBRE", SqlDbType.NVarChar)
                sql1.Parameters("@NOMBRE").Value = nombre
                tabla.Load(sql1.ExecuteReader())
            End If

        Catch ex As Exception
        Finally
            cn.Close()
        End Try
        Return tabla
    End Function


    'metodo para actualizar una localidad
    Public Function ActualizarRubro(ByVal id As Integer, ByRef nombre As String, ByRef descr As String) As Boolean
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Try
            cn.Open()
            Dim sql As New SqlCommand("rubros_EDITAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@ID_RUBRO", SqlDbType.Int)
            sql.Parameters("@ID_RUBRO").Value = id

            sql.Parameters.Add("@NOMBRE", SqlDbType.NVarChar)
            sql.Parameters("@NOMBRE").Value = nombre

            sql.Parameters.Add("@DESCRIPCION", SqlDbType.NVarChar)
            sql.Parameters("@DESCRIPCION").Value = descr

            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()

        End Try
    End Function



    '///////////////////////////////////////UNIDAD DE MEDIDA/////////////////////

    Public Function cargarTablaUM() As DataTable
        Dim tablaAux As New Data.DataTable
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Dim sql As String = "Select * from T_UNIDADES_MEDIDA"

        cn.Open()
        Dim cmd As New SqlCommand
        cmd.Connection = cn
        cmd.CommandText = sql
        cmd.CommandType = CommandType.Text

        tablaAux.Load(cmd.ExecuteReader())
        cn.Close()
        Return tablaAux

    End Function

    Public Function EliminarUM(ByVal pk As Integer) As Boolean

        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Try
            cn.Open()
            Dim sql As New SqlCommand("unidades_medida_ELIMINAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@ID_UNIDAD_MEDIDA", SqlDbType.Int)
            sql.Parameters("@ID_UNIDAD_MEDIDA").Value = pk

            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()
        End Try
    End Function


    Public Function GuardarUM(ByVal nombre As String, ByVal codigo As String, ByVal observ As String) As Boolean
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)

        Try
            cn.Open()
            Dim sql As New SqlCommand("unidades_medida_INSERTAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@NOMBRE", SqlDbType.NVarChar)
            sql.Parameters("@NOMBRE").Value = nombre

            sql.Parameters.Add("@CODIGO", SqlDbType.NChar)
            sql.Parameters("@CODIGO").Value = nombre

            If observ = "" Then
                sql.Parameters.Add("@OBSERVACIONES", SqlDbType.NVarChar)
                sql.Parameters("@OBSERVACIONES").Value = DBNull.Value
            Else
                sql.Parameters.Add("@OBSERVACIONES", SqlDbType.NVarChar)
                sql.Parameters("@OBSERVACIONES").Value = nombre
            End If

            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()

        End Try

    End Function


    Public Function buscarUMXNombre(ByVal nombre As String) As Data.DataTable 'metodo para filtrar localidades por el nombre
        Dim tabla As New Data.DataTable
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Dim sql As String = ""

        Try
            cn.Open()

            If nombre = "" Then 'pregunto si nombre viene vacio, es xq busco todos las localidades cargados
                sql = "select * from T_UNIDADES_MEDIDA"
                Dim cmd As New SqlCommand()

                cmd.Connection = cn
                cmd.CommandText = sql
                cmd.CommandType = CommandType.Text
                tabla.Load(cmd.ExecuteReader())

            Else
                Dim sql1 As New SqlCommand("unidades_medida_BUSCAR", cn)
                sql1.CommandType = CommandType.StoredProcedure

                sql1.Parameters.Add("@NOMBRE", SqlDbType.NVarChar)
                sql1.Parameters("@NOMBRE").Value = nombre
                tabla.Load(sql1.ExecuteReader())
            End If

        Catch ex As Exception
        Finally
            cn.Close()
        End Try
        Return tabla
    End Function

    Public Function buscarUMXCodigo(ByVal codigo As String) As Data.DataTable 'metodo para filtrar localidades por el nombre
        Dim tabla As New Data.DataTable
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Dim sql As String = ""

        Try
            cn.Open()

            If codigo = "" Then 'pregunto si nombre viene vacio, es xq busco todos las localidades cargados
                sql = "select * from T_UNIDADES_MEDIDA"
                Dim cmd As New SqlCommand()

                cmd.Connection = cn
                cmd.CommandText = sql
                cmd.CommandType = CommandType.Text
                tabla.Load(cmd.ExecuteReader())

            Else
                sql = "select * from T_UNIDADES_MEDIDA UM WHERE (UM.CODIGO LIKE '%'+@NOMBRE+'%')"
                Dim cmd As New SqlCommand()

                cmd.Parameters.AddWithValue("@NOMBRE", codigo)

                cmd.Connection = cn
                cmd.CommandText = sql
                cmd.CommandType = CommandType.Text
                tabla.Load(cmd.ExecuteReader())
            End If

        Catch ex As Exception
        Finally
            cn.Close()
        End Try
        Return tabla
    End Function


    Public Function ActualizarUM(ByVal id As Integer, ByRef nombre As String, ByRef codigo As String, ByVal obser As String) As Boolean
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Try
            cn.Open()
            Dim sql As New SqlCommand("unidades_medida_EDITAR", cn)
            sql.CommandType = CommandType.StoredProcedure

            sql.Parameters.Add("@ID_UNIDAD_MEDIDA", SqlDbType.Int)
            sql.Parameters("@ID_UNIDAD_MEDIDA").Value = id

            sql.Parameters.Add("@NOMBRE", SqlDbType.NVarChar)
            sql.Parameters("@NOMBRE").Value = nombre

            sql.Parameters.Add("@CODIGO", SqlDbType.NChar)
            sql.Parameters("@CODIGO").Value = codigo

            If obser = "" Then
                sql.Parameters.Add("@OBSERVACIONES", SqlDbType.NVarChar)
                sql.Parameters("@OBSERVACIONES").Value = DBNull.Value
            Else
                sql.Parameters.Add("@OBSERVACIONES", SqlDbType.NVarChar)
                sql.Parameters("@OBSERVACIONES").Value = obser
            End If

           
            sql.ExecuteNonQuery()
            Return True

        Catch ex As Exception
            Return False
        Finally
            cn.Close()

        End Try
    End Function


    '//////////////////////////////////////JACKY/////////////////////////////////////////

    
   
    'para insertar un rubro, JACKY  
    Public Sub insertarRubro(ByVal nombre As String, Optional ByVal descripcion As String = "")
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Dim cmd As New SqlCommand
        cn.Open()
        cmd.Connection = cn
        cmd.CommandType = CommandType.Text
        If descripcion <> "" Then
            cmd.CommandText = "insert into T_RUBROS values((select MAX(ID_RUBRO) from T_RUBROS)+1,'" & nombre & "','" & descripcion & "')"
        Else
            cmd.CommandText = "insert into T_RUBROS (ID_RUBRO, NOMBRE) values((select MAX(ID_RUBRO) from T_RUBROS)+1,'" & nombre & "')"
        End If
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub
    Public Sub insertarUnidad(ByVal nombre As String, ByVal codigo As String, Optional ByVal observacion As String = "")
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Dim cmd As New SqlCommand
        cn.Open()
        cmd.Connection = cn
        cmd.CommandType = CommandType.Text
        If observacion <> "" Then
            cmd.CommandText = "insert into T_UNIDADES_MEDIDA values((select MAX(ID_UNIDAD_MEDIDA) from T_UNIDADES_MEDIDA)+1,'"
            cmd.CommandText &= nombre & "','" & codigo & "','" & observacion & "'"
        Else
            cmd.CommandText = "insert into T_UNIDADES_MEDIDA values((select MAX(ID_UNIDAD_MEDIDA) from T_UNIDADES_MEDIDA)+1,'"
            cmd.CommandText &= nombre & "','" & codigo & "'"
        End If
    End Sub

    Public Sub modificarRubro(ByVal id As Integer, ByVal nombre As String, Optional ByVal descripcion As String = "")
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Dim cmd As New SqlCommand
        Dim tabla As New DataTable
        cn.Open()
        cmd.Connection = cn
        cmd.CommandType = CommandType.Text
        If descripcion <> "" Then
            cmd.CommandText = "update T_RUBROS set NOMBRE='" & nombre & "', DESCRIPCION='" & descripcion & "'"
            cmd.CommandText &= "where ID_RUBRO=" & id
        Else
            cmd.CommandText = "update T_RUBROS set NOMBRE='" & nombre & "', DESCRIPCION='" & DBNull.Value & "'"
            cmd.CommandText &= "where ID_RUBRO=" & id
        End If
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub
    Public Sub modificarUnidad(ByVal id As Integer, ByVal nombre As String, ByVal codigo As String, Optional ByVal observaciones As String = "")
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Dim cmd As New SqlCommand
        Dim tabla As New DataTable
        cn.Open()
        cmd.Connection = cn
        cmd.CommandType = CommandType.Text
        If observaciones <> "" Then
            cmd.CommandText = "update T_UNIDADES_MEDIDA set NOMBRE='" & nombre & "', CODIGO='" & codigo & "'"
            cmd.CommandText &= ", OBSERVACIONES='" & observaciones & "' where ID_UNIDAD_MEDIDA=" & id
        Else
            cmd.CommandText = "update T_UNIDADES_MEDIDA set NOMBRE='" & nombre & "', CODIGO='" & codigo & "'"
            cmd.CommandText &= ", OBSERVACIONES='" & DBNull.Value & "' where ID_UNIDAD_MEDIDA=" & id
        End If
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub
   
    Public Sub eliminarUnidad(ByVal id As Integer)
        Dim con As String = ConfigurationManager.ConnectionStrings("Conex").ConnectionString
        Dim cn As New SqlConnection(con)
        Dim cmd As New SqlCommand
        Dim tabla As New DataTable
        cn.Open()
        cmd.Connection = cn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "delete T_UNIDADES_MEDIDA where ID_RUBRO=" & id
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

End Class
